
require(['jquery', 'jquerymobile', 'net', 'dialogs'], function($, m, net, dia) {

    $('#setting_btn_menu').on('click', function(evt) {
        $('.ui-panel-inner').css({'padding':'0px'});
        $('.push_nees_opacity').css('min-height',$(window).height());
        console.log("sdjfklsd");
        $('#setting_content').css('max-height',$(window).height()-40);
        $('#setting_panel_menu').css('min-height',$(window).height());
        $('#setting_push_ul').css('min-height',$(window).height());
        $('#setting_auto_height').css('min-height',$(window).height()-354);
        console.log($('#setting_panel_menu').css('min-height'));
        console.log($('#setting_push_ul').css('min-height'));
        console.log($('#setting_auto_height').css('height'));
        var username = localStorage['username'] + '!';
        $("#setting_push_username").html(username);
        $( "#setting_panel_menu" ).panel( "open" );

    });

    // 点击新闻项，菜单隐藏,推出新闻页
    $('#setting_push_newsroom').off('click')
        .on('click', function(evt) {
        // Nick added for pull to refresh start
        initPageLoading("news_wrapper");
        // Nick added for pull to refresh end
            $.mobile.newChangePage("#newsroom",{ transition: "slide",reverse: false,changeHash: false});
    });

    // 点击 活动，菜单隐藏,推出活动页
    $('#setting_push_activities').off('click')
        .on('click', function(evt) {
        // Nick added for pull to refresh start
        initPageLoading("activities_wrapper");
        // Nick added for pull to refresh end
            $.mobile.newChangePage("#activities",{ transition: "slide",reverse: false,changeHash: false});
    });

	$('#setting_push_AR').off('click')
        .on('click', function(evt) {
           cordova.exec(function(){cordova.logger.debug("success");}, function(){cordova.logger.debug("error");}, "ShowVideoPlaybackView", "showVideoPlaybackView", []);
    });
	
    // 点击注销，返回登录
    $('#setting_push_logon').off('click')
        .on('click', function(evt) {
            $.mobile.newChangePage("#logon",{ transition: "slide",reverse: true,changeHash: false});

            //注销用户后复选框清空
            $('#all_check').removeClass('sel').addClass('nor');
            $('div[name="sbox"]').each(function(index, val) {
                $(val).removeClass('sel').addClass('nor');
            });
        // Nick added for pull to refresh start
        cleanUpListItems();
        $(".wrapper").find("#pullUp").hide();
        // Nick added for pull to refresh end
    });

    //点击进入修改密码页面
    $('#btn_setting_changePW').off('click')
        .on('click', function() {
            $.mobile.newChangePage("#forgetPassword",{ transition: "slide",reverse: false,changeHash: false});
        });

    // 点击进入关于App
    $('#btn_setting_about').off('click')
        .on('click', function(evt) {
            window.q['infomation_back'] = '#setting';
            $.mobile.newChangePage("#infomation",{ transition: "slide",reverse: false,changeHash: false});
        });

    // 点击进入团队信息
    $('#btn_setting_question').off('click')
        .on('click', function(evt) {
            window.q['question_back'] = '#setting';
            $.mobile.newChangePage("#page_question",{ transition: "slide",reverse: false,changeHash: false});
        });
    // 点击进入政策
    $('#btn_setting_policy').off('click')
        .on('click', function(evt) {
            window.q['policy_back'] = '#setting';
            $.mobile.newChangePage("#page_policy",{ transition: "slide",reverse: false,changeHash: false});
        });

    //推出setting页面
    $('#setting_push_setting').on('click', function(evt) {
        $( "#setting_panel_menu" ).panel( "close" );
    });

    //changePassword页面 设置内容高度是Header剩下的高度
    $("#setting").on( "pageshow", function( event ) {
        window.setBodyOverflow($(document.body));
        $('#setting_content').css('height',($(window).height()-40));
        $('#setting_ul').css('min-height', ($(window).height()-61));
		
		window.historyView = [];
        // Nick added for pull to refresh start
        window.shouldPageRefresh.newsroom = true;
        window.shouldPageRefresh.activities = true;
        // Nick added for pull to refresh end
    });

    // Nick added for pull to refresh start
    function cleanUpListItems() {
        $("#newsroom_listview_news").empty();
        $("#activities_listview_news").empty();
    }

    function initPageLoading(wrapper) {
        var $wrapper = $("#" + wrapper),
            $pullDownEl = $wrapper.find("#pullDown"),
            $pullDownLabel = $pullDownEl.find(".pullDownLabel");

        if ($wrapper.find("ul").html()) {
            $wrapper.find(".scroller").css(window.getVendorStyle("transform"), "translate(0, 0)");
            $pullDownEl.attr("class", "loading");
            $pullDownLabel.text("Loading...")
        }
    }
    // Nick added for pull to refresh end

    function compatibility() {
        /* Logon */
        $('#title_settings').parent()
            .css('display', 'block')
            .css('postion', 'relative');

        $('#title_settings').css('postion', 'absulute')
            .css('width', '65px')
            .css('height','20px')
            .css('margin', '8px auto auto auto');
    }


    $('#setting_push_Laisee').on('click', function(evt) {
        //Green Laisee entrance
        var cuser = null;
        if (localStorage.getItem('login_user')!=null) {
            cuser = JSON.parse(localStorage.getItem('login_user'));
        } else {
            console.assert(false, '还没登录，没有用户信息可填写');
        }
        cordova.exec(function(){console.log("success")}, function(){console.log("error")}, "OpenGreenLaisee", "openGreenLaisee", [JSON.stringify({"account": ""+cuser.staffId+"", "fullName": ""+cuser.english_name+"", "secureToken": "", "location": "CN"})]);
    });

    $(document).ready(function () {
        setTimeout(function() {
            // 兼容其他浏览器
            compatibility();
        },1000);
    });
});
